﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Toulr.Models;

public partial class Account_ChangePwd : LimitedPageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(IsPostBack)
        {
            if (string.IsNullOrEmpty(this.txtPwdOld.Value))
            {
                AddClientErrorMessageBox(null, "旧密码不能为空", null);
                this.txtPwdOld.Focus();
                return;
            }
            if(string.IsNullOrEmpty(this.txtPwdNew.Value))
            {
                AddClientErrorMessageBox(null, "新密码不能为空", null);
                this.txtPwdNew.Focus();
                return;
            }
            if (string.IsNullOrEmpty(this.txtPwdNewConfirm.Value))
            {
                AddClientErrorMessageBox(null,"确认密码不能为空");
                this.txtPwdNewConfirm.Focus();
                return;
            }
            if (!PageHelper.IsCorrectVerifyCode(txtVerifyCode.Value))
            {
                AddClientErrorMessageBox("错误提示", "校验码错误,请重新输入！");
                txtVerifyCode.Focus();
                return;
            }
            if(!this.CheckPwdOld(this.txtPwdOld.Value))
            {
                AddClientErrorMessageBox(null, "旧密码不正确，请重新输入", null);
                this.txtPwdOld.Focus();
                return;
            }
            if(this.txtPwdNew.Value!=this.txtPwdNewConfirm.Value)
            {
                AddClientErrorMessageBox(null, "两次密码输入不一致，请重新输入", null);
                this.txtPwdNew.Focus();
                return;
            }
            var actionResult =new ActionResult<object>(1,"ndy",null);//todo 调用个性密码方法
            if(actionResult==null)
            {
                Response.Redirect("../Error.aspx");
            }
            if(actionResult.ResultCode>0)
            {
                AddClientErrorMessageBox(null, "修改密码失败："+actionResult.Tips, null);
                return;
            }
            if(actionResult.ResultCode==0)
            {
                Response.Redirect("ChangePwdSuccess.aspx");
            }

        }
    }

    /// <summary>
    /// 检查旧密码是否正确
    /// </summary>
    /// <param name="pwdOld"></param>
    /// <returns></returns>
    [AjaxPro.AjaxMethod]
    public bool CheckPwdOld(string pwdOld)
    {
        //todo 未实现
        return true;
    }
}